package com.gexin.controller.system.user;

import com.gexin.core.web.SystemBaseController;
import com.gexin.model.system.AdminRole;
import com.gexin.model.system.AdminRoleRes;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.kit.JsonKit;
/**
 * 后台管理员模板
 * @author 肖得明
 *  用户权限组
 */
@ControllerBind(controllerKey = "/system/role/manage", viewPath = "WEB-INF/system/admin/")
public class AdminRolController extends SystemBaseController {

	//首页  查询所有的 一级菜单
	public void index(){
		setAttr("list", AdminRole.dao.getAll());
		render("role_list.html");
	}
	 
	//删除权限组
	public void delete(){
		if (AdminRoleRes.dao.findByRoleId(getParaToInt()).size()>0) {
			fail("该权限组正在被使用!");
		}else {
			AdminRole.dao.deleteById(getParaToInt());
			AdminRoleRes.dao.deleteByRoleId(getParaToInt());
			//RoleKit.RolMap.remove(getParaToInt());                                                                                                
			success();
		}
	}
	
	
	//添加或者修改权限组
	public void add_edit(){
		Integer id = getParaToInt();
		if(id!=null){
			setAttr("role", AdminRole.dao.findById(id));
		}
		setAttr("json", JsonKit.toJson(AdminRoleRes.dao.getRoleRes(id)));
		render("role_add_edit.html");
	}
	//保存权限信息
	public void save_role(){
		AdminRole role = getModel(AdminRole.class,"role");
		String roilelist = getPara("roilelist");
		if(role.getId()==null){
			//新增的
			role.save();
		}else{
			role.update();
		}
		AdminRole.dao.saveRole(role.getId(), roilelist);
		redirect("/system/role/manage/index");
	}

}


